Skip to content

feat: embed durableObjects exports into workers script #10117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Karakatiza666
Copy link

feature: simple embedding of file that exports Durable Objects classes
#1712

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

@changeset-bot
Copy link

changeset-bot bot commented Jun 7, 2023

⚠️ No Changeset found

Latest commit: fbed6ed

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ghostdevv
Copy link
Member

The last comment on the linked issue is from this time last year - is there not a better solution than having to edit an adapter at buildtime? Also is it a build or dev issue this is solving?

@Karakatiza666
Copy link
Author

@ghostdevv I am trying to solve a build issue, but it would work for both build and dev. There has to be an export for Durable Object class in the worker file - and I do not see how I can achieve this otherwise. I'd be happy if someone would confirm that's the best way to do it as of now.

@ghostdevv
Copy link
Member

ghostdevv commented Jun 8, 2023

The PR doesn't seem to work for me currently but I think it's because you aren't doing anything with the read file. However IMO we should probably take advantage of esbuild by copying the durable objects file to ${tmp}/durableObjects.ts and in the entry doing export * from './durableObjects'. The copy from path can default to ./src/durableObjects.js (or .ts) or be given from options like you have now.

Something like

// Copy durable objects
if (options.durableObjects) {
	builder.copy(options.durableObjects, `${tmp}/durableObjects.ts`)
} else {
	builder.copy(`${files}/durableObjects.js`, `${tmp}/durableObjects.ts`)
	builder.copy('./src/durableObjects.ts', `${tmp}/durableObjects.ts`)
	builder.copy('./src/durableObjects.js', `${tmp}/durableObjects.js`)
}

wdyt?

@Karakatiza666
Copy link
Author

Karakatiza666 commented Jun 8, 2023

Oh wow oops, I incorrectly copied my solution into PR. I have now amended the commit, please check it out!
I am not sure if there is need to copy with esbuild - after exports are embedded in the workers script they are successfully picked up in my Vite build. (I was able to successfully deploy a project with Durable Object binding)

@Karakatiza666
Copy link
Author

@ghostdevv did you have a chance to check out the update?

@ghostdevv
Copy link
Member

I am still not sure the best way to copy everything across, so trying to get a second opinion there.Regardless we'd still need to support TypeScript ootb, and I think we should set the default file to src/durableObjects.js (or ts) since we don't usually put special files in lib.

Another thing that just occurred to me is that when we document this, we need to note that sk specific imports like $lib won't work here because esbuild doesn't know about them. Unless there is some way we can get vite to process the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants